var clixpy_sess_id = "339907abd353f6715121639ca4243ffa";
var clixpy_impr_data = {
	291249 :"http://sess-339907abd353f6715121639ca4243ffa-i-291249.clixpy.com/clixpy_iframe.php?impression=291249&r=3264"
};
var clixpy_play_state = true;
var clixpy_domain = "clixpy.com";
var clixpy_last_impr = 291249;

var ClixpyPlayerManager = function() {
	this.w = window;
	this.d = document;
	this.data = clixpy_impr_data;
	this.is_running = clixpy_play_state;
	this.is_finished = false;
	this.sess_id = clixpy_sess_id;
	this.domain = clixpy_domain;
	this.last_impr = clixpy_last_impr
};
ClixpyPlayerManager.prototype.INIT = function() {
	var e = this;
	this.w.onload = function() {
		setInterval( function() {
			e.listen_instructions()
		}, 250)
	};
	this.set_cookie("ClixpyPlayerIN_" + this.sess_id, "");
	this.w.onerror = function(a, b, c, d) {
		return true
	}
};
ClixpyPlayerManager.prototype.play = function() {
	if (this.is_finished) {
		this.is_finished = false;
		for (i in this.data) {
			this.d.getElementById("player").src = this.data[i] + "&play=1";
			break
		}
		this.videoend_overlay_hide()
	} else {
		this.is_running = true;
		this.set_cookie("ClixpyPlayerIN_" + this.sess_id, "play");
		this.videoend_overlay_hide()
	}
};
ClixpyPlayerManager.prototype.pause = function() {
	this.is_running = false;
	this.set_cookie("ClixpyPlayerIN_" + this.sess_id, "pause")
};
ClixpyPlayerManager.prototype.listen_instructions = function() {
	var a = this.get_cookie("ClixpyPlayerOUT_" + this.sess_id);
	if (!a) {
		return
	}
	if (a == "end") {
		this.pause();
		this.set_impression_pager(this.last_impr);
		this.videoend_overlay_show();
		this.is_finished = true
	} else if (a.indexOf("impression-") != -1) {
		var b = a.replace(/impression-/ig, "");
		b = parseInt(b, 10);
		if (this.data[b]) {
			this.set_impression_pager(b)
		}
	} else if (a.indexOf("time-") != -1) {
		var c = a.replace(/time-/ig, "");
		c = parseInt(c, 10);
		if (!isNaN(c)) {
			this.set_impression_time(c)
		}
	}
	this.set_cookie("ClixpyPlayerOUT_" + this.sess_id, "")
};
ClixpyPlayerManager.prototype.videoend_overlay_show = function() {
	this.d.getElementById("videoend_hndlr").style.display = "block"
};
ClixpyPlayerManager.prototype.videoend_overlay_hide = function() {
	this.d.getElementById("videoend_hndlr").style.display = "none"
};
ClixpyPlayerManager.prototype.set_impression_pager = function(d) {
	var i = 0, c = false, nums = [], curr;
	for (curr in this.data) {
		if (d == curr) {
			c = parseInt(i, 10)
		}
		nums[i] = curr;
		i++
	}
	if (c === false) {
		return false
	}
	var e, mx;
	if (c <= 1) {
		e = 0;
		mx = Math.min(5, i) - 1
	} else if (c >= i - 3) {
		e = i - Math.min(5, i);
		mx = i - 1
	} else {
		e = c - 2;
		mx = c + 2
	}
	var f = {};
	for (i = e; i <= mx; i++) {
		f[i] = nums[i]
	}
	var g = this.d.getElementById("player_pager");
	if (!g) {
		return
	}
	while (g.firstChild) {
		g.removeChild(g.firstChild)
	}
	var a, b, obj = this;
	for (curr in f) {
		a = this.d.createElement("A");
		a.href = "javascript:;";
		a.setAttribute("clixpy_src", this.data[f[curr]]);
		a.className = f[curr] == d ? "active" : "";
		a.onclick = function() {
			obj.d.getElementById("player").src = this
					.getAttribute("clixpy_src")
					+ "&play=" + (obj.is_running ? 1 : 0);
			if (obj.is_running) {
				obj.set_cookie("ClixpyPlayerIN_" + obj.sess_id, "play")
			}
			obj.videoend_overlay_hide()
		};
		a.onfocus = function() {
			this.blur()
		};
		b = this.d.createElement("B");
		b.appendChild(this.d.createTextNode((parseInt(curr, 10) + 1) + " "));
		a.appendChild(b);
		g.appendChild(a)
	}
	this.d.getElementById("player_pager_current").innerHTML = c + 1
};
ClixpyPlayerManager.prototype.set_impression_time = function(a) {
	a = Math.round(a / 1000);
	var b = Math.floor(a / 60) + "";
	var c = (a % 60) + "";
	if (b.length == 1) {
		b = "0" + b
	}
	if (c.length == 1) {
		c = "0" + c
	}
	this.d.getElementById("player_time_current").innerHTML = b + ":" + c
};
ClixpyPlayerManager.prototype.trim = function(a) {
	if (typeof (a) != "string") {
		return a
	}
	a = a.replace(/^\s+/, "");
	a = a.replace(/\s+$/, "");
	return a
};
ClixpyPlayerManager.prototype.get_cookie = function(a) {
	var c = this.d.cookie;
	c = c.split(";");
	for ( var i = 0; i < c.length; i++) {
		c[i] = this.trim(c[i]);
		c[i] = c[i].split("=");
		if (c[i][0] == a && c[i][1] !== undefined) {
			return unescape(c[i][1])
		}
	}
	return null
};
ClixpyPlayerManager.prototype.set_cookie = function(a, b) {
	this.d.cookie = a + "=" + b + "; path=/; domain=." + this.domain + ";"
};